<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Connect
 *
 * @author dung
 */
class Connect
{

    //put your code here
    private $host = 'localhost';
    private $name = 'root';
    private $pwd = '';
    private $db;
    private $connect;
    private $port = '3306';
    private $rs = array();

    public function __construct($db)
    {
        $this->db = $db;
        $this->connection();
    }

    public function connection()
    {
        $this->connect = new mysqli($this->host, $this->name, $this->pwd, $this->db, $this->port);
        $this->connect->set_charset('utf-8');
        if (mysqli_connect_error()) {
            trigger_error('Error connecting to host ' . $this->connect->error, E_USER_ERROR);
        }
    }

    public function Exequery($querystring)
    {
        if (!$result = $this->connect->query($querystring)) {
            trigger_error('Error executing query: ' . $querystring . ' -  
         ' . $this->connect->error, E_USER_ERROR);
        } else {
            return $result->fetch_array(MYSQLI_ASSOC);
        }
    }

    public function QueryAll($queryString)
    {
        if (!$result = $this->connect->query($queryString)) {
            trigger_error('Error executing query: ' . $queryString . ' -  
         ' . $this->connect->error, E_USER_ERROR);
        } else {
            return $result;
        }
    }

}
